#!/bin/bash
SCRIPT_BASE_DIR=$( dirname "${BASH_SOURCE[0]}" )
source "${SCRIPT_BASE_DIR}/common/fs_utils.sh"

cmd=$( basename "$0" )

function usage() {
	echo "Usage: ${cmd} [ -t | -h ] [<root_dir>]"
    echo -e "\t-t: 增加对tools下python文件的索引"
    echo -e "\t-h: 显示帮助信息"
	exit 1
}

rootDir='.'
findBuildOpt='-name build* -type d -prune -o'
findToolsOpt="-name tools -type d -prune -o"
while getopts "th" args
do
    case "${args}" in 
        t)
            findToolsOpt=""
            shift
            ;;
        *)
            usage;;
    esac
done

if [ $# -gt 0 ]
then
    rootDir=$1
fi

echo "Root dir: $rootDir"

csFile="cscope.files"

echo "Build ${csFile} ..."
echo find ${rootDir} ${findBuildOpt} ${findToolsOpt} -name "*.py" -type f -print 
find ${rootDir} ${findBuildOpt} ${findToolsOpt} -name "*.py" -type f -print > "${csFile}"

echo "Build cscope DB..."
cscope -Rbqk
echo "Done."
